﻿Imports System.Data.SqlClient

Partial Class _Default
    Inherits System.Web.UI.Page
    Dim cn As New SqlConnection(ConfigurationSettings.AppSettings("conn"))
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim cmd As New SqlCommand("select imageid,imageurl,title,uploadby from imagetable order by uploaddate desc", cn)
            Dim ds As New SqlDataSource(cn.ConnectionString, cmd.CommandText)
            GridView1.DataSource = ds
            GridView1.DataBind()
        Catch
        End Try
    End Sub
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Dim cmd As New SqlCommand("select imageid,imageurl,title,uploadby from imagetable order by uploaddate desc", cn)
            Dim ds As New SqlDataSource(cn.ConnectionString, cmd.CommandText)
            GridView1.DataSource = ds
            GridView1.DataBind()
        Catch
        End Try
    End Sub
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cmd As New SqlCommand("select imageid,imageurl,title,uploadby from imagetable where uploadby='" + DropDownList1.SelectedValue + "' order by uploaddate desc", cn)
        Dim ds As New SqlDataSource(cn.ConnectionString, cmd.CommandText)
        GridView1.DataSource = ds
        GridView1.DataBind()
    End Sub
    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        Try
            'Dim iid As String = GridView1.Rows(GridView1.SelectedIndex).Cells(0).Text
            'cn.Open()
            'Dim cmd As New SqlCommand("delete from comment where imageid=" + iid, cn)
            'cmd.ExecuteNonQuery()
            'cn.Close()
            '
            'cn.Open()
            'cmd = New SqlCommand("select imageurl from imagetable where imageid=" + iid, cn)
            'Dim delfilename As String = cmd.ExecuteScalar
            'cn.Close()
            '
            'cn.Open()
            'cmd = New SqlCommand("delete from imagetable where imageid=" + iid, cn)
            'cmd.ExecuteNonQuery()
            'cn.Close()

            'System.IO.File.Delete(Server.MapPath(delfilename))
            Dim delfilename As String
            delfilename = functions.deletepicture(GridView1.Rows(GridView1.SelectedIndex).Cells(0).Text)
            System.IO.File.Delete(Server.MapPath(delfilename))
            GridView1.DataBind()

            GridView1.SelectedIndex = -1

        Catch
        End Try

    End Sub
End Class
